//
// Created by xili on 2024/8/30 21:50.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    int maximumBags(vector<int> &capacity, vector<int> &rocks, int additionalRocks) {
        vector<int> left;
        int n = capacity.size();
        for (int i = 0; i < n; i++) {
            left.push_back(capacity[i] - rocks[i]);
        }
        sort(left.begin(), left.end());
        int i = 0;
        for (; i < n; i++) {
            if (additionalRocks >= left[i]) {
                additionalRocks -= left[i];
            } else {
                break;
            }
        }
        return i;
    }
};